package com.app.server.impl;

import com.app.mapper.PopularScienceMapper;
import com.app.mapper.StatuteMapper;
import com.app.model.PopularScienceModel;
import com.app.model.StatuteModel;
import com.app.server.PopularScienceService;
import com.app.server.StatuteService;
import com.app.utils.StringTool;
import com.app.vo.PopularScienceVo;
import com.app.vo.StatuteVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StatuteServiceImpl extends ServiceImpl<StatuteMapper, StatuteModel> implements StatuteService {
    @Autowired
    private StatuteMapper statuteMapper;
    // 查询列表
    @Override
    public StatuteVo getPopularList(Integer page, Integer limit, String title) {
        Page<StatuteModel> page1 = new Page<>(page, limit);

        QueryWrapper<StatuteModel> qw =new QueryWrapper<>();
        if (StringTool.isNotEmpty(title)){
            qw.like("title",title);
        }
        qw.orderByDesc("id");
        Page<StatuteModel> popularPage = statuteMapper.selectPage(page1, qw);
        List<StatuteModel> popularList = popularPage.getRecords();

        long count = popularPage.getTotal();
        StatuteVo popularScienceVo = new StatuteVo();
        popularScienceVo.setList(popularList);
        popularScienceVo.setCount((int) count);
        return popularScienceVo;
    }
}
